﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HCommon;
using System.Threading;
namespace eStock
{
    public partial class frmHello : Form
    {
        public frmHello()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        private void KhoiTaoDuLieu()
        {
            try
            {
                string errMsg = "";
                if (Dao.Get_Connect("server=.;user id=sa;password=123456;database=eStock;Connection Reset=FALSE", ref errMsg) == false) 
                {
                    Dialog.ShowMess(Dialog.mType.err, errMsg);
                    this.Close();
                    return;
                }
                this.Hide();
                Application.Run(new frmLogin());
                this.Close();
            }
            catch (Exception ex)
            {
                Common.GhiLog("frmHello_Load", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
                Application.Exit();
            }
        }

        private void frmHello_Shown(object sender, EventArgs e)
        {
            try
            {
                Thread tienTrinh = new Thread(new ThreadStart(KhoiTaoDuLieu));
                tienTrinh.SetApartmentState(ApartmentState.STA);
                tienTrinh.Start();
            }
            catch (Exception ex)
            {
                Common.GhiLog("frmHello_Load", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
                Application.Exit();
            }
        }
    }
}
